package com.cgsd.heyu.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;

import com.android.library.adapter.BaseMultiItemAdapter;
import com.android.library.adapter.ClickTypeListener;
import com.android.library.adapter.ViewHolder;
import com.android.library.utils.DpPxUtil;
import com.android.library.utils.StringUtils;
import com.cgsd.heyu.R;
import com.cgsd.heyu.entity.TabEntity;

import java.util.List;

/**
 * @author xiaoxing
 * Description 反馈图片
 * CreateData: 2020/11/10
 */
public class FeedbackImageAdapter extends BaseMultiItemAdapter<TabEntity> {
    /**
     * 是否是删除模式
     */
    private ClickTypeListener clickTypeListener;

    public void setClickTypeListener(ClickTypeListener clickTypeListener) {
        this.clickTypeListener = clickTypeListener;
    }

    public FeedbackImageAdapter(Context mContext, List<TabEntity> mDatas) {
        super(mContext, mDatas);
    }

    @Override
    protected int muItemViewType(int position, TabEntity tabEntity) {
        return 0;
    }

    @Override
    protected int muLayoutId(int itemType) {
        return R.layout.item_feedback_image;
    }

    @Override
    public void convert(ViewHolder holder, TabEntity tabEntity, int position) {
        ImageView ivDelete = holder.getView(R.id.iv_delete);
        if (StringUtils.isEmpty(tabEntity.imgUrl)){
            holder.setImageId(R.id.iv_bg,R.mipmap.btn_feedback_addphoto);
            ivDelete.setVisibility(View.GONE);
        }else {
            holder.setImageUrlCircularAll(R.id.iv_bg, tabEntity.imgUrl, DpPxUtil.dip2px(mContext, 8));
            ivDelete.setVisibility(View.VISIBLE);
        }
        ivDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (clickTypeListener != null){
                    clickTypeListener.clickTypePosition(v, -1,position);
                }
            }
        });
    }

}
